package com.ruoyi.web.controller.info;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.info.domain.VinfoDriver;
import com.ruoyi.info.service.IVinfoDriverService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 驾驶人信息Controller
 *
 * @author oy
 * @date 2022-12-16
 */
@RestController
@RequestMapping("/info/driver")
public class VinfoDriverController extends BaseController
{
    @Resource
    private IVinfoDriverService vinfoDriverService;

    /**
     * 查询驾驶人信息列表
     */
    @PreAuthorize("@ss.hasPermi('info:driver:list')")
    @GetMapping("/list")
    public TableDataInfo list(VinfoDriver vinfoDriver)
    {
        startPage();
        List<VinfoDriver> list = vinfoDriverService.selectVinfoDriverList(vinfoDriver);
        return getDataTable(list);
    }

    /**
     * 导出驾驶人信息列表
     */
    @PreAuthorize("@ss.hasPermi('info:driver:export')")
    @Log(title = "驾驶人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VinfoDriver vinfoDriver)
    {
        List<VinfoDriver> list = vinfoDriverService.selectVinfoDriverList(vinfoDriver);
        ExcelUtil<VinfoDriver> util = new ExcelUtil<VinfoDriver>(VinfoDriver.class);
        util.exportExcel(response, list, "驾驶人信息数据");
    }

    /**
     * 获取驾驶人信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:driver:query')")
    @GetMapping(value = "/{driverId}")
    public AjaxResult getInfo(@PathVariable("driverId") Long driverId)
    {
        return success(vinfoDriverService.selectVinfoDriverByDriverId(driverId));
    }

    /**
     * 新增驾驶人信息
     */
    @PreAuthorize("@ss.hasPermi('info:driver:add')")
    @Log(title = "驾驶人信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VinfoDriver vinfoDriver)
    {
        return toAjax(vinfoDriverService.insertVinfoDriver(vinfoDriver));
    }

    /**
     * 修改驾驶人信息
     */
    @PreAuthorize("@ss.hasPermi('info:driver:edit')")
    @Log(title = "驾驶人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VinfoDriver vinfoDriver)
    {
        return toAjax(vinfoDriverService.updateVinfoDriver(vinfoDriver));
    }

    /**
     * 删除驾驶人信息
     */
    @PreAuthorize("@ss.hasPermi('info:driver:remove')")
    @Log(title = "驾驶人信息", businessType = BusinessType.DELETE)
	@PutMapping("/{driverIds}")
    public AjaxResult remove(@PathVariable Long[] driverIds)
    {
        return toAjax(vinfoDriverService.deleteVinfoDriverByDriverIds(driverIds));
    }


    @PreAuthorize("@ss.hasAnyRoles('admin,common')")
    @GetMapping("/selectitem")
    public AjaxResult getDriverIdAndName(String name)
    {
        System.out.println("=====name======"+name);
        return AjaxResult.success(vinfoDriverService.getDriverIdAndNameList(name));
    }

}
